var MAX_LENGYH = 1100 //删除最大的数量后，不再进行删除
var SEARCH = "待处理"  //搜索文档
var count = 0;       //计数
var timeRecord = 0         //消耗时间

function createTimeOut(interval) {
  setTimeout(() => {
    let dom = document.querySelectorAll(".RecycleTable-module_columnsAction_Am8SF .RecycleTable-module_normal_N-qK2")
    if (dom.length > 0) {
      dom.forEach(function (item, i) {
        if (count > MAX_LENGYH) { }
        if (i == 0) {
          ++count
          item.click()
          setTimeout(() => {
            document.querySelector(".ant-popover-buttons .ant-btn-primary").click()
            var timeRandom = Math.floor(Math.random() * 300 + 1000)
            timeRecord += timeRandom
            console.log(count, timeRandom + " ms", timeRecord + " ms", `总共消耗时间:${parseInt(timeRecord / 1000)}s`)
            createTimeOut(timeRandom)
          }, Math.floor(Math.random() * 200 + 1000));
        }
      })
    } else if (count < MAX_LENGYH && dom.length === 0) {
      setTimeout(() => {
        document.querySelector(".ant-input").value = SEARCH
        document.querySelector(".ant-input").focus()
        var event = new Event('keydown', { bubbles: true, cancelable: false });
        event.keyCode = 13; //模拟空格键
        document.querySelector(".ant-input").dispatchEvent(event);
        setTimeout(() => {
          let dom = document.querySelectorAll(".RecycleTable-module_columnsAction_Am8SF .RecycleTable-module_normal_N-qK2")
          if (dom.length !== 0) {
            var timeRandom = Math.floor(Math.random() * 500 + 1500)
            timeRecord += timeRandom
            console.log(count, timeRandom + "ms", timeRecord + "ms")
            createTimeOut(timeRandom)
          } else {
            console.log("回收站没有搜索数据，结束了", `总共消耗时间:${parseInt(timeRecord / 1000)}s`)
          }
        }, 1000);
      }, 200);
    }
  }, interval);
}

createTimeOut(2000)
